﻿//https://github.com/Siccity/Dialogue/blob/master/Scripts/Nodes/Branch.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XNode;

[System.Serializable]
public class Connection { }

public class AnimationNode : Node
{
    private static CoroutineHelper _internalCoroutineHelper = null;
    private static CoroutineHelper CoroutineHelper
    {
        get
        {
            if (_internalCoroutineHelper == null)
            {
                GameObject go = new GameObject();
                _internalCoroutineHelper = go.AddComponent<CoroutineHelper>();
            }
            return _internalCoroutineHelper;
        }
    }

    [System.Serializable]
    public class TriggerData
    {
        public string TriggerName;
        public string StateName;
    }
    public TriggerData[] Triggers;

    public string StateName;
    public AnimationClip AnimationClip;

    public bool UsesTriggers = false;
    public List<string> StatesToTransitionTo = new List<string>();

    [Input]
    public Connection Input;
    [Output]
    public Connection Output;

    public void OnEnter()
    {
        if (!AnimationClip.isLooping)
        {
            CoroutineHelper.StartCoroutine(AnimationCoroutine(AnimationClip.length));
            Continue();
        }
    }

    private IEnumerator AnimationCoroutine(float time)
    {
        yield return new WaitForSeconds(time);

    }

    public void Continue(string triggerName = null)
    {
        bool emptyTrigger = string.IsNullOrEmpty(triggerName);
        bool triggerCountIsZero = Triggers.Length == 0;

        NodePort port = null;

        if (emptyTrigger || triggerCountIsZero)
        {
            port = GetOutputPort("Output");
        }
        else
        {

        }
    }
}
